<%#
  # WebROaR - Ruby Application Server - http://webroar.in/
  # Copyright (C) 2009  Goonj LLC
  #
  # This file is part of WebROaR.
  #
  # WebROaR is free software: you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # WebROaR is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with WebROaR.  If not, see <http://www.gnu.org/licenses/>.
  #%>
<%if @exceptions.size >0 %>
<% if current_status == OPEN_EXCEPTION %>
  <h3><center> Open Exceptions</center></h3>
<% elsif current_status == CLOSED_EXCEPTION %>
  <h3><center> Closed Exceptions</center></h3>
<% elsif current_status == IGNORED_EXCEPTION %>
  <h3><center> Ignored Exceptions</center></h3>
<% elsif current_status == PERMANENTLY_IGNORED_EXCEPTION %>
  <div class='text_align_right'>
    <%=link_to_remote 'Exception Classes', :update => 'data_div', :url => {:controller => 'exceptions', :action => 'save_exception_class_form' , :app_name => @application_name}%>
  </div>
  <h3><center> Permanently Ignored Exceptions</center></h3>
<% end %>
<span class='error'><%= flash[:notice] if flash[:notice] %></span>
<%= form_tag '', :id => 'form_exception_list',:name => 'form_exception_list' do -%>
<table width = 90% align='center'>
    <tr>
    	<th  width = 1%> <%= check_box_tag 'check_all', 'check_all', false, :onclick =>"checkAll(this,document.form_exception_list.exception_ids_)" %> </td>
      <th  width = 39%>Exception</td>
      <th  width = 20%>Class</td>
      <th  width = 20%>URL</td>  
      <th  width = 2%>Occurrences</td>
      <th  width = 18%>Time</td>      
    </tr>
  <%@exceptions.each do |exception|%>
    <tr id="exception_<%= exception.id %>">
    	<td> <%= check_box_tag 'exception_ids[]', exception.id,false, :onclick => "uncheckMain(this)" %> </td>
      <td><%= link_to_remote "#{ truncate(exception.exception_message, :length => 80)}", :update => 'data_div', :url => {:controller => 'exceptions', :action => 'show', :id => exception.id, :app_name => @application_name, :status_name => status_name, :page => @exceptions.current_page} %> </td>
      <td><%= exception.exception_class%></td>
      <td><%= exception.controller%>/<%=exception.method%></td>
      <td><%= exception.exceptions_count%></td>
      <td><%= exception.latest_detail.wall_time.strftime("%d-%b-%Y %H:%M:%S")%></td>
    </tr>
  <%end%>
<% end -%>
    <tr>
    	<td colspan = 6>
    		<b>Take Action:</b>
				<% unless current_status == OPEN_EXCEPTION %>
				  <b><%=link_to_remote 'Reopen', :condition => "checkMarked('Reopen')", :url => {:controller => 'exceptions', :action => 'change_status', :status_name => "open", :current_status => status_name, :app_name => @application_name, :page => @exceptions.current_page }, :submit => 'form_exception_list' %></b>
				<% end %>
				<% unless current_status == CLOSED_EXCEPTION %> 
				  <b><%=link_to_remote 'Close', :condition => "checkMarked('Close')", :url => {:controller => 'exceptions', :action => 'change_status', :status_name => "close", :current_status => status_name, :app_name => @application_name, :page => @exceptions.current_page }, :submit => 'form_exception_list'  %></b>
			  <% end %>
				<% unless current_status == IGNORED_EXCEPTION %>
				<b><%=link_to_remote 'Ignore', :condition => "checkMarked('Ignore')", :url => {:controller => 'exceptions', :action => 'change_status', :status_name => "ignore", :current_status => status_name, :app_name => @application_name, :page => @exceptions.current_page }, :submit => 'form_exception_list' %></b>
				<% end %>
				<span style='margin-left:21%;'>
				  ( <%= @exceptions.offset + 1 %> to <%= @exceptions.size + @exceptions.offset %> of <%= @exceptions.total_entries %> )
				</span>
				<%#=link_to_remote 'Delete', :condition => "checkMarked('delete')", :url => {:controller => 'exceptions', :action => 'change_status', :status_name => "delete", :current_status => status_name, :app_name => @application_name, :page => @exceptions.current_page }, :submit => 'form_exception_list' %>
    	</td>
	  </tr>
	  <% if will_paginate @exceptions %>
      <tr>
        <td colspan = 6>
          <%= will_paginate @exceptions, :params => {:controller => 'exceptions', :action => 'list_statuswise_exceptions', :app_name => @application_name, :status_name => status_name ,:per_page => session[:per_page]} %>
        </td>
      </tr>
    <% end %>
    <tr>
      <th colspan='6'>
        <div class='text_align_right'>
          Size : <%=select 'per', 'page',%w{5 10 15 20 25 30},:selected => params[:per_page] || session[:per_page]%>
          <%= observe_field 'per_page',:url => {:controller => 'exceptions', :action => 'list_statuswise_exceptions', :app_name => @application_name, :status_name => status_name}, :with => 'per_page'%>
        </div>
      </th>
    </tr>
  </table>

<%else%>
  <% if current_status == OPEN_EXCEPTION %>
    No open exceptions currently for this application.
	<% elsif current_status == CLOSED_EXCEPTION %>
	  No closed exceptions currently for this application.
	<% elsif current_status == IGNORED_EXCEPTION %>
	  No ignored exceptions currently for this application.
	<% elsif current_status == PERMANENTLY_IGNORED_EXCEPTION %>
    <div class='text_align_right'>
      <%=link_to_remote 'Exception Classes', :update => 'data_div', :url => {:controller => 'exceptions', :action => 'save_exception_class_form' , :app_name => @application_name}%>
    </div>
    No permanently-ignored exceptions currently for this application.
	<% end %> 
<%end%>
